<style>
.layui-input-block{
margin-left:120px;
}
</style>
<form class="layui-form" action="" id="orderEditForm" style="position: absolute;">
	<div class="layui-row"  style="margin-top:10px;">
		<input class="layui-input" type="hidden" name="roleId" id = "roleId" th:value="${roleId}">
		<input class="layui-input" type="hidden" name="id" id = "id" value="">
		<div id="role" class="layui-input-block" style="width:380px;height:300px;overflow-y:auto;margin-top:10px;margin-left:10px;">
			 <ul id="roleTree" class="ztree" style="margin-top:0; width:160px;"></ul>	
		</div>
	</div>

	<div class="layui-row" style="margin-top:70px;">
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12" style="text-align:center;">
          <button class="layui-btn" lay-submit="" lay-filter="formSubmit">提交</button>
      	<button type="button" class="layui-btn layui-btn-primary" id="closeBtn">关闭</button>
    </div>
    </div>
</form>

<script>
layui.use('form', function(){
	 var form = layui.form;
	 form.render();
	 //表单提交
	 form.on('submit(formSubmit)',function(data) {
		 onCheck();
		 $.ajax({
			 type: "GET",
			 url: "/sys/role/table/roleinit",
	         data: $("#orderEditForm").serializeJson(),
	         dataType: "json",
	         success: function(data) {
	        	if(data.code == 200) {
	        		//关闭弹出层
	        		layer.msg(data.message);
	        		layer.close(editdialogindex);
	        	}else{
	        		layer.msg(data.message,{icon: 2});
	        	} 
	         }
		 });
		 return false;
	 });
// ztree 设置
var setting = {
		check:{
			enable: true,
			chkStyle: "checkbox"
			,chkboxType: { "Y": "p", "N": "s" }
		},
        view: {
            dblClickExpand: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
//             beforeClick: beforeClick,
//            onCheck:onCheck
        }
    };
//获取所有选中节点
function onCheck(){
   var treeObj=$.fn.zTree.getZTreeObj("roleTree"),
   nodes=treeObj.getCheckedNodes(true),
   v="";
   for(var i=0;i<nodes.length;i++){
   v += nodes[i].id + ',';
//    alert(nodes[i].id); //获取选中节点的值
   }
   $("#id").attr("value",v);
}
$(document).ready(function(){
	 $.ajax({
            type: "post",
            url: "/sys/role/findAllMenu?id="+$("#roleId").val(),
            type:"post",
			 contentType:"application/json",
            success: function(data){
            	if(data.code==200){
  					 $.fn.zTree.init($("#roleTree"), setting, data.result);
            	}else{
            		layer.msg(data.message)
            	}
            }
		});
});
function reloadData(){
	$(".layui-laypage-btn")[0].click();//页面的确定按钮
}
$('#closeBtn').click(function() {
	layer.close(editdialogindex);
});
});
</script>